<?php
/**
 * 网管管理类
 *
 * @auther 大耳牛
 * 2016-12-31
 **/
namespace Home\Model;
use Think\Model;
class RoomModel extends Model{
	//定义表名称
	protected $tableName = 'room';
	
	/**
	 * 获取房间列表总数
	 *
	 **/
	public function getRoomListCount(){
		return $this->count();
	}
	
	/**
	 * 获取房间列表
	 *
	 **/
	public function getRoomList($page){
		return $this->alias('room')
					->join('left join momoda_lock as slock on room.room_id = slock.room_id')
					->join('left join momoda_network as network on slock.network_id = network.network_id')
					->field('room.*, slock.cmd_id, network.network_id, network.network_nums')
					->order('room.room_id asc')
					->page($page, C('PAGE_SIZE'))
					->select();
	}
	
	/**
	 * 房间信息保存
	 *
	 **/
	public function addRoomInfo($data){
		$this->data($data)->add();
	}
	
	/**
	 * 删除房间信息
	 * @param int $room_id 房间ID
	 **/
	public function delRoomInfo($room_id){
		return $this->where(array('room_id' => $room_id))->delete();
	}
	
	/**
	 * 编辑房间信息
	 * @param int $room_id
	 * @param Array $data 编辑资料
	 **/
	public function editRoomInfo($room_id, $data){
		return $this->where(array('room_id' => $room_id))->save($data);
	}
	
	/**
	 * 查询房间详情
	 * @param int $room_id
	 **/
	public function getRoomInfoById($room_id){
		return $this->where(array('room_id' => $room_id))->find();
	}
	
	public function getRoomInfoByNumber($room_number){
		return $this->where(array('room_number' => $room_number))->find();
	}
}